<?php
include("inc/head.php");
//  `FID`,  `TID`,  `FName`,  `TFName`,  `FType` ,  `TFType`,  `FLength`,  `FIndex`,  `Config`,  `UID`,  `CreateTime`,  `Depositing`,  `ProgramCode`,  `DefaultVal`

$fieldStr = array('FName','TFName','FType','Depositing','TFType','FLength','ListOrder','ExecOrder','EditOrder');
$nameStr = array('字段名','数据库字段名','字段类型','是否入库','数据库字段类型','字段长度','列表顺序','执行顺序','编辑顺序');
for($i=0;$i<count($fieldStr);$i++)
{
	$sqlStr .= $fieldStr[$i].", ";
	$titleStr .= "<td>{$nameStr[$i]}</td>";
}

$TID = $_GET['TID'];
if(!$TID)
	alert("请选择模板","location","templateList.php");
$page = $_GET['page'];
$order = $_GET['order'];
$start = 0;
$pagesize = 20;

if(!$page)
	$page = 1;
$start = ($page - 1) * $pagesize;

if(!$order)
	$order = "ListOrder";
else
	$order = ereg_replace("[\'\"\-;]","",$order);

$sql = "select * from Field where TID='$TID' order by $order";


if($_POST['doPost'] == "true")
{
	$IDS = $_POST["ID"];
	if(!is_array($IDS))
	{
		alert("请选择要操作的文档");
	}
	if($_POST['action'] == "del")
	{
		$sqlstr = implode(",",$IDS);
		$sql = "delete from Field where FID in ($sqlstr)";
		if($db->query($sql))
		{
			new ActionLog(array("LogType"=>"field_del","Action"=>"$sqlstr\t{$currAdmin->AID}"));
			alert("删除成功","location",$_SERVER["SCRIPT_NAME"]);
		}
	}
	exit;
}


?>
<form method="post" onsubmit="return confirm('该操作不可恢复，确认进行该操作');">
<input type="hidden" value="true" name="doPost">
<input type="hidden" value="<?php echo $TID;?>" name="TID">
<div>
	<a href="javascript:history.back();" style="color:#F00; margin-right:20px;" >返回上一页</a>  
	<a href='field.php?TID=<?php echo $TID;?>'>新建模板域</a>
	 <a href="template.php?TID=<?php echo $TID;?>">编辑模板</a> 
	 <a href="bin/doc_<?php echo $TID;?>.php">新建文档</a> 
	 <a href="bin/docList_<?php echo $TID;?>.php">文档列表</a>
</div>
<table width="90%" cellpadding="1" cellspacing="1" class="list-div">
	<tr>
		<th colspan="<?php echo count($fieldStr)+1; ?>" style="text-align:left">模板域列表 Table_<?php echo $TID;?></th>   
    </tr>
	<tr style="font-weight:bold">
		<td>ID</td><?php
echo $titleStr;
		?>
	</tr>
	<?php
	$result = $db->query($sql);
	while($row = $db->fetch_array($result))
	{
	?>
	<tr>
		<?php
echo "<td><input type=\"checkbox\" value=\"{$row[FID]}\" name=\"ID[]\"><a href=\"field.php?TID=$TID&FID={$row[FID]}\" target=\"_self\">{$row[FID]}</a></td>";
for($i=0;$i<count($fieldStr);$i++)
{
echo "<td>".$row[$fieldStr[$i]]."</td>";
}
		?>
	</tr>
	<?php
	}
	?>
	<tr>
		<td><input type="radio" name="action" value="del">删除</td>
		<td colspan="<?php echo count($fieldStr);?>"><input type="submit" name="sub" value="提交"></td>
	</tr></table>
<?php
include("inc/foot.php");
?>
